<?php


namespace App\Jobs\QiPao;

use App\Enums\ActivityCodeEnum;
use App\Jobs\Job;
use App\Services\Accompany\AccompanyOrderService;
use App\Services\Activity\ActivityNewServerService;
use App\Services\Tools\IdempotentConsume;
use Illuminate\Support\Facades\Log;

class AccompanyCancelJob extends Job
{
    protected $job;
    protected $orderId;
    const jobName = 'AccompanyCancelJob';

    public function __construct($orderId)
    {
        $this->orderId = $orderId;
    }

    public function handle()
    {
        if (env('APP_ENV') != 'production') {
            Log::error('AccompanyCancelJob:' . json_encode(['time' => getMillisecond(), 'orderId' => $this->orderId]));
        }


        try {
            $orderId                 = $this->orderId;
            $uk                      = $orderId;
            $idempotentConsumeServer = new IdempotentConsume();
            if ($idempotentConsumeServer->checkIdempotentRedisKey(self::jobName, $uk)) {
                $service = new AccompanyOrderService();

                $service->timeOutCancelOrder($orderId);
                //校验主播订单是否回复
                $service->verifyAnchorOrderChat($orderId);
            }

        } catch (\Exception $exception) {
            $idempotentConsumeServer->deleteIdempotentRedisKey(self::jobName, $uk);
            Log::error('ActivityNewServerJob:' . $exception->getMessage());
        }
    }
}